package cn.pconline.autoclub.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author chensy
 */
public class RegionUtil {

    //港澳台的区域存中国标准区域，这里8和港澳台只做辅助用
    private final static String[] regionNames = new String[]{"华北", "华东", "华中", "华南", "西南", "西北", "东北", "港澳台"};
    //private final static long[] regionIds = new long[]{1, 2, 3, 4, 5, 6, 7, 8};
    public final static long[] sortedRegionIds = new long[]{2, 4, 3, 1, 6, 5, 7, 8};//指定顺序

    public static String getRegionName(long regionId) {
        int index = (int) regionId - 1;
        if (regionId < 1 || regionId > 8) {
            return "";
        }
        return regionNames[index];
    }
    //按顺序对就好的 id 和 name
    private final static HashMap<Long, Long> regionMap = new HashMap<Long, Long>();
    private final static HashMap<String, Long> provinceMap = new HashMap<String, Long>();

    static {
        //省份数据来自个人中心
        provinceMap.put("北京市", 110000L);
        provinceMap.put("天津市", 120000L);
        provinceMap.put("河北省", 130000L);
        provinceMap.put("山西省", 140000L);
        provinceMap.put("内蒙古", 150000L);

        provinceMap.put("上海市", 310000L);
        provinceMap.put("山东省", 370000L);
        provinceMap.put("江苏省", 320000L);
        provinceMap.put("安徽省", 340000L);
        provinceMap.put("江西省", 360000L);
        provinceMap.put("浙江省", 330000L);
        provinceMap.put("福建省", 350000L);
        provinceMap.put("台湾省", 710000L);

        provinceMap.put("湖北省", 420000L);
        provinceMap.put("湖南省", 430000L);
        provinceMap.put("河南省", 410000L);

        provinceMap.put("广东省", 440000L);
        provinceMap.put("广西", 450000L);
        provinceMap.put("海南省", 460000L);
        provinceMap.put("香港", 810000L);
        provinceMap.put("澳门", 820000L);

        provinceMap.put("重庆市", 500000L);
        provinceMap.put("四川省", 510000L);
        provinceMap.put("贵州省", 520000L);
        provinceMap.put("云南省", 530000L);
        provinceMap.put("西藏", 540000L);

        provinceMap.put("陕西省", 610000L);
        provinceMap.put("甘肃省", 620000L);
        provinceMap.put("宁夏", 640000L);
        provinceMap.put("新疆", 650000L);
        provinceMap.put("青海省", 630000L);

        provinceMap.put("黑龙江省", 230000L);
        provinceMap.put("吉林省", 220000L);
        provinceMap.put("辽宁省", 210000L);
        
        provinceMap.put("台湾省", 710000L);
        provinceMap.put("香港", 810000L);
        provinceMap.put("澳门", 820000L);
        
        //分区与省份的映射
        regionMap.put(getProvinceId("北京市"), 1L);
        regionMap.put(getProvinceId("天津市"), 1L);
        regionMap.put(getProvinceId("河北省"), 1L);
        regionMap.put(getProvinceId("山西省"), 1L);
        regionMap.put(getProvinceId("内蒙古"), 1L);

        regionMap.put(getProvinceId("上海市"), 2L);
        regionMap.put(getProvinceId("山东省"), 2L);
        regionMap.put(getProvinceId("江苏省"), 2L);
        regionMap.put(getProvinceId("安徽省"), 2L);
        regionMap.put(getProvinceId("江西省"), 2L);
        regionMap.put(getProvinceId("浙江省"), 2L);
        regionMap.put(getProvinceId("福建省"), 2L);
        regionMap.put(getProvinceId("台湾省"), 2L);

        regionMap.put(getProvinceId("湖北省"), 3L);
        regionMap.put(getProvinceId("湖南省"), 3L);
        regionMap.put(getProvinceId("河南省"), 3L);

        regionMap.put(getProvinceId("广东省"), 4L);
        regionMap.put(getProvinceId("广西"), 4L);
        regionMap.put(getProvinceId("海南省"), 4L);
        regionMap.put(getProvinceId("香港"), 4L);
        regionMap.put(getProvinceId("澳门"), 4L);

        regionMap.put(getProvinceId("重庆市"), 5L);
        regionMap.put(getProvinceId("四川省"), 5L);
        regionMap.put(getProvinceId("贵州省"), 5L);
        regionMap.put(getProvinceId("云南省"), 5L);
        regionMap.put(getProvinceId("西藏"), 5L);

        regionMap.put(getProvinceId("陕西省"), 6L);
        regionMap.put(getProvinceId("甘肃省"), 6L);
        regionMap.put(getProvinceId("宁夏"), 6L);
        regionMap.put(getProvinceId("新疆"), 6L);
        regionMap.put(getProvinceId("青海省"), 6L);

        regionMap.put(getProvinceId("黑龙江省"), 7L);
        regionMap.put(getProvinceId("吉林省"), 7L);
        regionMap.put(getProvinceId("辽宁省"), 7L);
        
        regionMap.put(getProvinceId("台湾省"), 8L);
        regionMap.put(getProvinceId("香港"), 8L);
        regionMap.put(getProvinceId("澳门"), 8L);

    }

    private static long getProvinceId(String provinceName) {
        Long id = provinceMap.get(provinceName);
        if (id == null) {
            return 0;
        } else {
            return id;
        }
    }

    public static long getRegionId(long provinceId) {
        Long id = regionMap.get(provinceId);
        if (id == null) {
            return 0;
        } else {
            return id;
        }
    }
    /**
     * http://club.pcauto.com.cn/all/
     * 查找车友会的省份
     */
    public final static String[] provinceForSearch = {"广东省", "上海市", "北京市", "吉林省", "辽宁省", "河北省", "天津市", "江苏省", "山东省", "浙江省", "山西省", "内蒙古", "安徽省", "福建省", "江西省", "河南省", "湖北省", "湖南省", "广西", "海南省", "重庆市", "四川省", "贵州省", "云南省", "西藏", "陕西省", "甘肃省", "青海省", "宁夏", "新疆", "台湾省", "香港", "澳门", "黑龙江"};
    public final static String[] provinceIdForSearch = {"440000", "310000", "110000", "220000", "210000", "130000", "120000", "320000", "370000", "330000", "140000", "150000", "340000", "350000", "360000", "410000", "420000", "430000", "450000", "460000", "500000", "510000", "520000", "530000", "540000", "610000", "620000", "630000", "640000", "650000", "710000", "810000", "820000", "230000"};
    
    //直辖市代表
    public final static long[] proIds = {110000,120000,310000,500000,710000,810000,820000};  //分别是 ：北京，天津，上海，重庆，台湾，香港，澳门
    public static final List<Long> specialProIds = new ArrayList<Long>();
    static {
    	for(long proId :proIds){
        	specialProIds.add(proId);
        }
    }
    
}
